import EventBus from "../../../../utils/EventBus";

Component({
  data: {
    loading: false,
    finished: false,
    popupVisible: false,
    isLoading: false,
    currentItem: null,
    dialogVisible: false,
    toastRef: null,
  },
  props: {
    name: '',
    list: [],
    generateStatus: false,
  },
  methods: {
    handleRef(ref) {
      this.setData({
        toastRef: ref
      })
    },

    showItem(e) {
      const { item } = e.target.dataset
      this.setData({
        popupVisible: true,
        currentItem: item
      })
      EventBus.emit('updateStatus', this.props.name, item.key)
    },

    confirm() {
      this.setData({
        popupVisible: false
      })
      if (this.props.name === 'order') return
      this.data.toastRef.show({
        message: '恭喜获得20个租币',
        description: '阅读信息',
        money: 20
      })
    },

    remove() {
      this.setData({
        popupVisible: false,
        dialogVisible: true,
      })
    },

    onRemove() {
      EventBus.emit('removeByKey', this.props.name, this.data.currentItem.key)
      this.setData({
        dialogVisible: false
      })
    },

    onCancel() {
      this.setData({
        dialogVisible: false
      })
    }
  },
});
